<template>
	<div class="view">
		<div class="header">
			<div class="h_exit" @click="toIndex">
				<i class="i-exit i-20 i-mr-10"></i>
				<div class="h_str">返回上一页</div>
			</div>
			<div class="h_con">
				<div class="h_li">用户管理</div>
			</div>
		</div>

		<div class="main">
			<div class="main_con">
				<div class="m_title">用户管理</div>
				<div class="line">
					<div class="search">
						<el-input placeholder="请输入关键词" suffix-icon="el-icon-search" v-model="keywords"
							@change="search" size="medium" style="width: 200px;">
						</el-input>
						<el-select v-model="userType" placeholder="请选择类型" style="width: 200px;margin-right: 10px">
							<el-option v-for="item in options" :key="item.title" :label="item.title"
								:value="item.sort">
							</el-option>
						</el-select>
						<el-button type="primary" size="medium" @click="search">搜索</el-button>
					</div>
				</div>

				<div class="table">
					<el-table style="width: 100%;" :data="dataList" :height="table_height">
						<el-table-column type="selection" min-width="5%" align="center">
						</el-table-column>
						<el-table-column type="index" :index="1" label="行号" min-width="10%" align="center">
						</el-table-column>
                        <el-table-column prop="type" label="类型" min-width="15%" align="center">
							<template slot-scope="scope">
								<span>{{ scope.row.type==1?"企业":"求职者" }}</span>
							</template>
						</el-table-column>
                        <el-table-column prop="openid" label="微信标识" min-width="15%" align="center">
						</el-table-column>
                        <el-table-column prop="hname" label="联系方式" min-width="20%" align="center">
						</el-table-column>
                        <el-table-column prop="timeCreate" label="注册时间" min-width="20%" align="center">
						</el-table-column>
						<el-table-column prop="time" label="是否有效" min-width="15%" align="center">
							<template slot-scope="scope">
								<el-switch v-model="scope.row.isOk" active-color="#13ce66" inactive-color="#A5ADBA"
									:active-value="1" :inactive-value="0" @change="isOkHandler(scope.row)">
								</el-switch>
							</template>
						</el-table-column>
						<!-- <el-table-column prop="teacher" label="操作" min-width="30%" align="center">
							<template slot-scope="scope">
								<el-button size="mini" plain @click="edit(scope.row)">编辑</el-button>
								<el-button size="mini" plain @click="remove(scope.row)" v-if="isRole('data_remove')">移除</el-button>
							</template>
						</el-table-column> -->
					</el-table>
				</div>
				<div class="item_bottom">
					<div class="item_num">共{{ total }}条信息</div>
					<div class="item_page">
						<el-pagination background layout="prev, pager, next" :total="total"
							@current-change="handleCurrentChange">
						</el-pagination>
					</div>
				</div>
			</div>
		</div>

	</div>
</template>

<script>
import Top from "@/components/top.vue"
export default {
	components: {
		Top,
	},
	data() {
		return {
			options: [
				{
					title: "全部",
					sort: null,
				},
				{
					title: "企业",
					sort: 1,
				},
				{
					title: "求职者",
					sort: 2,
				}
			],
			keywords: "",
			table_height: document.documentElement.clientHeight - 360,
			diaHeight: document.documentElement.clientHeight - 142,
			dataList: [],
			total: 10,
			li_num: 1,
			left: 0,
			current: 1,
			limit: 10,
			userType:null,
		}

	},
	methods: {

		// 是否有效
		isOkHandler(item) {
			this.$http({
				url: this.$api.accountSetIsOk+item.id+"/"+item.isOk,
				method: 'get',
			}).then(res => {
				if (res.data.code == 20000) {
					this.$message.success(res.data.message)
				} else {
                    item.isOk = item.isOk==0? 1:0
					this.$message.error(res.data.message)
				}
			})
		},

		// 搜索
		search() {
			this.current = 1
			this.dataInit()
		},
		toIndex() {
			this.$router.push('/')
		},
		enter(num) {
			if (num == 1) {
				this.left = 0
			} else {
				this.left = 110
			}
		},

		leave() {
			if (this.li_num == 1) {
				this.left = 0
			} else {
				this.left = 110
			}
		},

		li_click(num) {
			this.li_num = num
			if (num == 2) {
				this.$router.push('/role')
			}
		},

		// 打开上传图片弹窗
		imgUpload() {
			this.cropperModel = true
		},

		dataInit() {
			this.$http({
				'method': 'post',
				'url': this.$api.accountList,
				data: {
					current: this.current,
					limit: this.limit,
					keywords: this.keywords,
					type:this.userType
				}
			}).then(res => {
				if (res.data.code == 20000) {
					this.dataList = res.data.data.list
					this.total = res.data.data.total
				}
			})
		},


		// 分页
		handleCurrentChange(num) {
			this.current = num;
			this.dataInit();
		},
	},
	created() {
		this.dataInit()
	}

}
</script>

<style scoped>
@import url(../../assets/css/class.css);
>>> .el-input__inner{
	height: 36px;
	line-height: 36px;
	color: #60626682;
}
</style>
